#MP Moralization and Foreign Policy Attitudes Replication File: All code necessary to replicate pre-test results reported in Appendix A
### Last updated: 3 June 2025

###Analyses carried out using R version 4.4.3 in RStudio version 2024.04.2+764 on Lenovo ThinkPad X1 Carbon Gen 12 Intel Core Ultra 7 155U, 1700 Mhz, 12 running Windows 11 Enterprize
#Run all code in the order that it appears! 

#uncomment to install if needed:
#install.packages("stargazer")

library(foreign)
library(stargazer)

#Load the data
setwd() #Set your working directory to the folder containing the data
data <- read.csv("MP_study1_pretest_data.csv")

# Prune the data for bots or non-U.S. respondents ---------------------------------------------------------
#Respondents who declined consent (n=37) excluded from replication data in preliminary step

full <- nrow(data) #690

#Retain US participants based on IP
x <- which(data$IP_country=="United States")
data <- data[x,] #688

#Drop participants flagged as bots by recaptcha
x <- which(data$Q_RecaptchaScore<=0.5)
data <- data[-x,] #685 remaining

#Drop participants flagged as bots by relevantID fraud score (>= 30)
x <- which(data$Q_RelevantIDFraudScore>=30)
data <- data[-x,] #672 remaining

nrow(data) #672 US adults retained for analysis

full - nrow(data) # excludes the 18 responses originating outside the U.S. or flagged as bots

# Variable coding functions ---------------------------------------------------------

#Function to rescale variables to range from 0 to 1
rescale <- function(x){
  return((x-min(x,na.rm=TRUE))/(max(x-min(x,na.rm=TRUE),na.rm=TRUE)))
}

#Function to recode variables
recode <- function(variable, reverse=FALSE, maxVal, minVal, binarize=FALSE, x=NA, x2){
  if (is.factor(variable)){variable <- as.numeric(variable)}
  if (missing(maxVal)){maxVal <- max(variable, na.rm=TRUE)}
  if (missing(minVal)){minVal <- min(variable, na.rm=TRUE)}
  variable[variable > maxVal] <- NA
  variable[variable < minVal] <- NA
  if (reverse){
    temp <- variable
    for (j in 1:maxVal){
      temp[which(variable==j)] <- maxVal-j+1
    }
    return(temp)
  }
  if (binarize){
    if (is.na(x)){stop("Specify the value to dichotomize on")}
    temp <- variable
    if (missing(x2)){
      i <- which(variable == x)
      k <- which(variable < x | variable > x)
    }
    else{
      i <- which(variable >= x & variable <= x2)
      k <- which(variable < x | variable > x2)
    }
    temp[i] <- 1
    temp[k] <- 0
    return(temp)
  }
  return(variable)
}





# Coding data: Demographics ------------------------------------------------------------

#Gender
data$man <- recode(data$gender, binarize =TRUE, x="1") #1 if man, 0 if else

#Age
data$age1 <- recode(data$age, binarize=TRUE, x=1, x2=2) #18-34
data$age2 <- recode(data$age, binarize=TRUE, x=3) #35-44
data$age3 <- recode(data$age, binarize=TRUE, x=4, x2=5) #45-64
data$age4 <- recode(data$age, binarize=TRUE, x=6, x2=8) #65 + 

#Party/ideology

##Party 
data$rep <- recode(data$pid3, binarize=TRUE, x=1) #Republican
data$dem <- recode(data$pid3, binarize=TRUE, x=2) #Democrat
data$ind <- recode(data$pid3, binarize=TRUE, x=3, x2=4) #Independent or something else

data$pid7 <- ifelse(data$rep==1 & data$pidrep==1, 7,
                      ifelse(data$rep==1 & data$pidrep==2, 6,
                             ifelse(data$ind==1 & data$pidlean==2, 5,
                                    ifelse(data$ind==1 & data$pidlean==3, 4,
                                           ifelse(data$ind==1 & data$pidlean==1, 3,
                                                  ifelse(data$dem==1 & data$piddem==2, 2,
                                                         ifelse(data$dem==1 & data$piddem==1, 1, NA)))))))
data$pid71 <- rescale(data$pid7) #7 point party scale, higher values = strong republican

#Party IDs with leaners
data$pidreplean <- ifelse(data$pid7 > 4, 1,
                            ifelse(data$pid7 < 5, 0, NA))
data$piddemlean <- ifelse(data$pid7 < 4, 1,
                            ifelse(data$pid7  >3 , 0, NA))
data$pidtrueind <- ifelse(data$pid7 == 4, 1,
                            ifelse(data$pid7>4 | data$pid7<4 , 0, NA))

data$ideo1 <- rescale(data$ideo) #Higher = liberal


#Political interest
data$polint1 <- rescale(data$polint) #Higher = extremely interested

#Race
data$white <- recode(data$race, binarize=TRUE, x=3) #White/Caucasian

#Latino origin
data$latinor <- recode(data$latino, binarize=TRUE, x=2) # Yes hispanic or latino origin

#Non-hispanic white
data$nhwhite <- ifelse(data$white==1 & data$latinor==0, 1, 
                         ifelse(data$white==0 | (data$white==1 & data$latinor==1), 0, NA))

#Education
data$university <- recode(data$educ, binarize=TRUE, x=5, x2=8) #university education


#Treatment 
data$treatment[data$treatment==""] <- NA

data$reasons <- as.numeric(recode(data$treatment, binarize=TRUE, x="reasons")) #reasons group


# Appendix A Footnote 1: Attention check --------------------------------------------------------

data$acheck1correct <- recode(data$attcheck1, binarize=TRUE, x=3)

prop.acheck <- prop.table(table(data$acheck1correct))

round(prop.acheck[2], digits=3)*100 #79.7% correctly answered the attention check


# Coding the Foreign Policy questionnaire --------------------------------------------------------

#For each, code DK to midpoint (for now); combine the DVs from each treatment group to single variable

#Human Rights
data$hr1r <- ifelse(data$hr1==6, 3, data$hr1)
data$hr2r <- ifelse(data$hr2==6, 3, data$hr2)

#no reasons
data$hr1cr <- ifelse(data$hr1c==6, 3, data$hr1c)
data$hr2cr <- ifelse(data$hr2c==6, 3, data$hr2c)


#Combine to single variable across treatment groups
data$hr1comb <- ifelse(is.na(data$hr1r), data$hr1cr, data$hr1r)
data$hr2comb <- ifelse(is.na(data$hr2r), data$hr2cr, data$hr2r)


#Climate
data$climate1r <- ifelse(data$climate1==6, 3, data$climate1)
data$climate2r <- ifelse(data$climate2==6, 3, data$climate2)

#no reasons
data$climate1cr <- ifelse(data$climate1c==6, 3, data$climate1c)
data$climate2cr <- ifelse(data$climate2c==6, 3, data$climate2c)


#Combine to single variable across treatment groups
data$climate1comb <- ifelse(is.na(data$climate1r), data$climate1cr, data$climate1r)
data$climate2comb <- ifelse(is.na(data$climate2r), data$climate2cr, data$climate2r)


#Aid
data$aid1r <- ifelse(data$aid1==6, 3, data$aid1)
data$aid2r <- ifelse(data$aid2==6, 3, data$aid2)

#no reasons
data$aid1cr <- ifelse(data$aid1c==6, 3, data$aid1c)
data$aid2cr <- ifelse(data$aid2c==6, 3, data$aid2c)

#Combine to single variable across treatment groups
data$aid1comb <- ifelse(is.na(data$aid1r), data$aid1cr, data$aid1r)
data$aid2comb <- ifelse(is.na(data$aid2r), data$aid2cr, data$aid2r)


#Security
data$security1r <- ifelse(data$security1==6, 3, data$security1)
data$security2r <- ifelse(data$security2==6, 3, data$security2)

#no reasons
data$security1cr <- ifelse(data$security1c==6, 3, data$security1c)
data$security2cr <- ifelse(data$security2c==6, 3, data$security2c)

#Combine to single variable across treatment groups
data$security1comb <- ifelse(is.na(data$security1r), data$security1cr, data$security1r)
data$security2comb <- ifelse(is.na(data$security2r), data$security2cr, data$security2r)


#cooperation
data$cooperation1r <- ifelse(data$cooperation1==6, 3, data$cooperation1)
data$cooperation2r <- ifelse(data$cooperation2==6, 3, data$cooperation2)

#no reasons
data$cooperation1cr <- ifelse(data$cooperation1c==6, 3, data$cooperation1c)
data$cooperation2cr <- ifelse(data$cooperation2c==6, 3, data$cooperation2c)

#Combine to single variable across treatment groups
data$cooperation1comb <- ifelse(is.na(data$cooperation1r), data$cooperation1cr, data$cooperation1r)
data$cooperation2comb <- ifelse(is.na(data$cooperation2r), data$cooperation2cr, data$cooperation2r)


#economic
data$economic1r <- ifelse(data$economic1==6, 3, data$economic1)
data$economic2r <- ifelse(data$economic2==6, 3, data$economic2)

#no reasons
data$economic1cr <- ifelse(data$economic1c==6, 3, data$economic1c)
data$economic2cr <- ifelse(data$economic2c==6, 3, data$economic2c)

#Combine to single variable across treatment groups
data$economic1comb <- ifelse(is.na(data$economic1r), data$economic1cr, data$economic1r)
data$economic2comb <- ifelse(is.na(data$economic2r), data$economic2cr, data$economic2r)


#Additive scales for each

data$hrscale <- rescale((data$hr1comb + data$hr2comb))
data$climatescale <- rescale((data$climate1comb + data$climate2comb))
data$aidscale <- rescale((data$aid1comb + data$aid2comb))
data$securityscale <- rescale((data$security1comb + data$security2comb))
data$cooperationscale <- rescale((data$cooperation1comb + data$cooperation2comb))
data$economicscale <- rescale((data$economic1comb + data$economic2comb))



# Coding the Moral conviction variables ----------------------------------------------

data$hr1_corecomb <- ifelse(is.na(data$hr1_core), data$hr1c_core, data$hr1_core)
data$hr1_fundcomb <- ifelse(is.na(data$hr1_fund), data$hr1c_fund, data$hr1_fund)

data$hr2_corecomb <- ifelse(is.na(data$hr2_core), data$hr2c_core, data$hr2_core)
data$hr2_fundcomb <- ifelse(is.na(data$hr2_fund), data$hr2c_fund, data$hr2_fund)


data$climate1_corecomb <- ifelse(is.na(data$climate1_core), data$climate1c_core, data$climate1_core)
data$climate1_fundcomb <- ifelse(is.na(data$climate1_fund), data$climate1c_fund, data$climate1_fund)

data$climate2_corecomb <- ifelse(is.na(data$climate2_core), data$climate2c_core, data$climate2_core)
data$climate2_fundcomb <- ifelse(is.na(data$climate2_fund), data$climate2c_fund, data$climate2_fund)

data$aid1_corecomb <- ifelse(is.na(data$aid1_core), data$aid1c_core, data$aid1_core)
data$aid1_fundcomb <- ifelse(is.na(data$aid1_fund), data$aid1c_fund, data$aid1_fund)

data$aid2_corecomb <- ifelse(is.na(data$aid2_core), data$aid2c_core, data$aid2_core)
data$aid2_fundcomb <- ifelse(is.na(data$aid2_fund), data$aid2c_fund, data$aid2_fund)

data$security1_corecomb <- ifelse(is.na(data$security1_core), data$security1c_core, data$security1_core)
data$security1_fundcomb <- ifelse(is.na(data$security1_fund), data$security1c_fund, data$security1_fund)

data$security2_corecomb <- ifelse(is.na(data$security2_core), data$security2c_core, data$security2_core)
data$security2_fundcomb <- ifelse(is.na(data$security2_fund), data$security2c_fund, data$security2_fund)

data$cooperation1_corecomb <- ifelse(is.na(data$cooperation1_core), data$cooperation1c_core, data$cooperation1_core)
data$cooperation1_fundcomb <- ifelse(is.na(data$cooperation1_fund), data$cooperation1c_fund, data$cooperation1_fund)

data$cooperation2_corecomb <- ifelse(is.na(data$cooperation2_core), data$cooperation2c_core, data$cooperation2_core)
data$cooperation2_fundcomb <- ifelse(is.na(data$cooperation2_fund), data$cooperation2c_fund, data$cooperation2_fund)

data$economic1_corecomb <- ifelse(is.na(data$economic1_core), data$economic1c_core, data$economic1_core)
data$economic1_fundcomb <- ifelse(is.na(data$economic1_fund), data$economic1c_fund, data$economic1_fund)

data$economic2_corecomb <- ifelse(is.na(data$economic2_core), data$economic2c_core, data$economic2_core)
data$economic2_fundcomb <- ifelse(is.na(data$economic2_fund), data$economic2c_fund, data$economic2_fund)


#Create Additive scales for each

data$hr1moral <- rescale((data$hr1_corecomb + data$hr1_fundcomb))
data$hr2moral <- rescale((data$hr2_corecomb + data$hr2_fundcomb))

data$climate1moral <- rescale((data$climate1_corecomb + data$climate1_fundcomb))
data$climate2moral <- rescale((data$climate2_corecomb + data$climate2_fundcomb))

data$aid1moral <- rescale((data$aid1_corecomb + data$aid1_fundcomb))
data$aid2moral <- rescale((data$aid2_corecomb + data$aid2_fundcomb))

data$security1moral <- rescale((data$security1_corecomb + data$security1_fundcomb))
data$security2moral <- rescale((data$security2_corecomb + data$security2_fundcomb))

data$cooperation1moral <- rescale((data$cooperation1_corecomb + data$cooperation1_fundcomb))
data$cooperation2moral <- rescale((data$cooperation2_corecomb + data$cooperation2_fundcomb))

data$economic1moral <- rescale((data$economic1_corecomb + data$economic1_fundcomb))
data$economic2moral <- rescale((data$economic2_corecomb + data$economic2_fundcomb))


#Pooled
data$hrmoral <- rescale((data$hr1moral + data$hr2moral))
data$climatemoral <- rescale((data$climate1moral + data$climate2moral))
data$aidmoral <- rescale((data$aid1moral + data$aid2moral))
data$securitymoral <- rescale((data$security1moral + data$security2moral))
data$cooperationmoral <- rescale((data$cooperation1moral + data$cooperation2moral))
data$economicmoral <- rescale((data$economic1moral + data$economic2moral))



# Appendix A Table A2: Providing information does not affect moral conviction: Human rights, climate, and aid----------------------

mod.hr1.moral <- lm(hr1moral ~ reasons, data=data) 
mod.hr2.moral <- lm(hr2moral ~ reasons, data=data)

mod.climate1.moral <- lm(climate1moral ~ reasons, data=data)
mod.climate2.moral <- lm(climate2moral ~ reasons, data=data)

mod.aid1.moral <- lm(aid1moral ~ reasons, data=data)
mod.aid2.moral <- lm(aid2moral ~ reasons, data=data)

mods.reasons.a2 <- list(mod.hr1.moral, mod.hr2.moral, mod.climate1.moral, mod.climate2.moral, mod.aid1.moral, mod.aid2.moral) #combine because stargazer cannot handle long model names

stargazer(mods.reasons.a2, 
          title="Providing information does not affect moral conviction: Human rights, climate, and aid", omit.stat=c("LL", "ser", "f", "adj.rsq"), style="apsr", digits=3, label="tab:reasonsfx_1",
          covariate.labels=c("Reasons Treatment"), star.cutoffs=c(0.05, 0.01)) #column labels added in tex


# Table A3: Providing information does not affect moral conviction: Security, Institutions, and Economy----------------------

mod.security1.moral <- lm(security1moral ~ reasons, data=data)
mod.security2.moral <- lm(security2moral ~ reasons, data=data)

mod.cooperation1.moral <- lm(cooperation1moral ~ reasons, data=data)
mod.cooperation2.moral <- lm(cooperation2moral ~ reasons, data=data)

mod.economic1.moral <- lm(economic1moral ~ reasons, data=data)
mod.economic2.moral <- lm(economic2moral ~ reasons, data=data)

mods.reasons.a3 <- list(mod.security1.moral, mod.security2.moral, mod.cooperation1.moral, mod.cooperation2.moral, mod.economic1.moral, mod.economic2.moral) #combine because stargazer cannot handle long model names

stargazer(mods.reasons.a3, 
          title="Providing information does not affect moral conviction: Security, Institutions, and Economy", omit.stat=c("LL", "ser", "f", "adj.rsq"), style="apsr", digits=3, label="tab:reasonsfx_2",
          covariate.labels=c("Reasons Treatment"), star.cutoffs=c(0.05, 0.01)) #column labels added in tex


